package core.controls;
import ibm.widgets.WLink;
import ibm.widgets.WRadioButton;

import com.rational.test.ft.object.interfaces.TestObject;
import com.rational.test.util.regex.Regex;

import core.exceptions.ResultFailureException;
import core.testcases.TestObj;
/**
 * Description   : Functional Test Script
 * @author angel.tsvetkov
 */
public class RadioButton extends Control<WRadioButton>
{
	public RadioButton(String propertyValue, String propertyName,
			String objClass, TestObject parent, String descriptiveName) {
		super(propertyValue, propertyName, objClass, parent, descriptiveName);
		// TODO Auto-generated constructor stub
	}

	/**
	 * Description :  Select radio button
	 * 
	 * @param propValue - property value which is used for radio button determination
	 * 
	 * @param propName - property name which is used for radio button determination
	 * 
	 * @param parent - area in which the radio button belongs.
	 */
	public boolean select() throws ResultFailureException {
		// Initialize variables
		boolean result = false;
		WRadioButton radioButtonToSelect = null;

		// Perform select radio button
		try {
			//Allocate Radio button
			radioButtonToSelect = this.get();
			
			//Click it
			radioButtonToSelect.click();

			result = true;
		} catch (Exception e) {
			throw new ResultFailureException(
					"Unexpected assertion on selecting " + this.getDescriptiveName());
		}
		finally
		{
			//Unregister object
			radioButtonToSelect.unregister();
		}

		return result;
	}

	@Override
	public WRadioButton get() {
		if(this.isCognosControl())
		{
			TestObject parent = this.getParent();
			this.obj = new WRadioButton(parent.getChildren()[0]);
		}
		else
		{
			Regex toSerach = new Regex(this.PropValue(), Regex.MATCH_MULTILINE);
			this.obj = new WRadioButton(toSerach,this.PropName(),this.getObjClass(),this.getParent());
		}
		return this.obj;
	}

	@Override
	public boolean isEnabled() {
		return this.get().isEnabled();
	}

	@Override
	public boolean isExist() {
		return this.get().ensureObjectIsVisible();
	}
}


